package app.Disthanitian.thaistyle.EmerMez;

import java.util.ArrayList;

import android.util.Log;

import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.PolygonOptions;

public class PositionInRiskZone {

	private MainActivity ma;
	private PolygonOptions rectGon;
	//private PolylineOptions rectLine;
	ArrayList<LatLng> latLng[];
	double lat1[],lng1[],lat2[],lng2[];
	
	
	public boolean isInPolygon(ArrayList<LatLng>[] riskArray,LatLng position){
		
		ma = new MainActivity();
		latLng = new ArrayList[riskArray.length];
		latLng = riskArray;		
		boolean check = false;
		
		for(int i=0;i<latLng.length;i++){			
				for(int j =0;j<latLng[i].size();j++){
					Log.d("Number"+i+":: Point"+j,""+latLng[i].get(j).latitude+","+latLng[i].get(j).longitude);
					Log.d("Number"+i+":: Point"+j,""+(latLng[i].get(j).latitude+0.00005)+","+(latLng[i].get(j).latitude-0.00005));
					Log.d("Number"+i+":: Point"+j,""+(latLng[i].get(j).longitude+0.00005)+","+(latLng[i].get(j).longitude-0.00005));
					if(position.longitude <= latLng[i].get(j).longitude+0.00005){
						
						if(position.longitude >= latLng[i].get(j).longitude-0.00005){
							
							if(position.latitude <= latLng[i].get(j).latitude+0.00005){
								
								if(position.latitude >= latLng[i].get(j).latitude-0.00005){
									check = true;
									Log.d("checking",""+check);
									break;
								}
							}
						}
					
					}
				}
				if(check)
					break;
		}
		return check;
	}
				
	public boolean isVertical(ArrayList<LatLng> x){
		double x1[],y1[],checkX1,checkX2,checkY1,checkY2;
		boolean result = false;
		x1 = new double[x.size()];
		y1 = new double[x.size()];
		int count =0;
		for(LatLng d : x){
			x1[count] = d.latitude;
			y1[count] = d.longitude;
			count++;
		}
		checkX1 = x1[0]-0.0010;
		checkX2 = x1[0]+0.0010;
		checkY1 = y1[0]-0.0010;
		checkY2 = y1[0]+0.0010;
		for(int i=0;i<y1.length;i++){
			if(((y1[i] > (checkY1)) && (y1[i] < (checkY2)))){
				result = true;
			}else{
				result = false;
			}
		}
		return result;
	}

}
	
